let qq = require("/sdcard/脚本/QQ.js");
qq.init();
FloatyUtil(); //=悬浮窗加载===
init();
toastLog("加载校验文字识别~~版本：24.7.4");
sleep(5000);
threads.start(function () {
  findAndClick("允许|立即开始");
});
if (!requestScreenCapture()) {
  toast("请求截图失败");
  exit();
}
setScreenMetrics(1080, 2400);
let height = device.height;
let width = device.width;
let 记录运行时间 = 0;
// 刷视频("抖音极速版");

抖音极速版逛逛();
拼多多();
快手极速版任务();
// 去桌面("任务结束~~");
exit();
function 快手极速版任务() {
  showFLog("开始快手极速版任务");
  if (!lunchApp("快手极速版")) {
    return;
  }
  home();
  打开快手极速版页面();
  校验关闭图片();
  点击赚钱();
  if (!widgetCheck("任务中心", 8000)) {
    back();
    点击赚钱();
  }
  开宝箱任务();
  校验关闭图片();
  sleep(3000);
  看广告();
  back();
  findAndClick("放弃.*");
  搜索();
  打开快手极速版页面();
  刷视频("快手极速版");
  if (app.launchApp("快手极速版分身")) {
    校验关闭图片();
    点击赚钱();
    if (!widgetCheck("任务中心", 8000)) {
      back();
      点击赚钱();
    }
    findAndClick("我知道了");
    开宝箱任务();
    校验关闭图片();
    搜索();
    看广告();
  }
  findAndClick("首页");
  刷视频("快手极速版");
  showFLog("结束快手极速版任务");
}
//======================
function 退出广告() {
  if (findAndClick("已成功.*|领取成功.*", 35000)) {
    showFLog("随机等待3-5秒");
    sleep(random(3000, 5000));
    back();
    sleep(1000);
    let 再看一个 = findAndClick("放弃.*|拒绝|坚持退出");
    if (再看一个 && !/放弃/.test(再看一个.text())) {
      findAndClick("已成功.*", 35000);
      showFLog("随机等待3-5秒");
      sleep(random(3000, 5000));
      back();
      再看一个 = findAndClick("放弃.*|领取.*|再看一个");
      if (再看一个 && !/放弃/.test(再看一个.text())) {
        findAndClick("坚持退出");
      }
    } else {
      back();
    }
  } else {
    return true;
  }
}
function 看广告() {
  for (let index = 0; index < 20; index++) {
    if (!findAndClick("看广告得.*金币")) {
      console.info("看视频的金币没有查询到");
      break;
    }
    sleep(3000);
    if (widgetGetOne("首页")) {
      showFLog("校验到首页按键，退出");
      break;
    }
    if (退出广告()) {
      log("没有查到广告倒计时，退出看广告");
      break;
    }
  }
  点击赚钱();
}
function 搜索() {
  let 搜索赚金币 = widgetGetOne("搜索.*赚金币");
  if (搜索赚金币 && !/搜索赚金币/.test(搜索赚金币.text())) {
    setClip(搜索赚金币.text().replace("搜索“", "").replace("”赚金币", ""));
    findAndClick("搜索.*赚金币");
    sleep(3000);
    paste();
    findAndClick("搜索");
    sleep(3000);
    back();
    sleep(1000);
    back();
    sleep(1000);
  }
}
function 开宝箱任务() {
  if (findAndClick("开宝箱得金币|我知道了")) {
    back();
  }
  sleep(1000);
  校验关闭图片();
}

function 校验关闭图片() {
  let 圈X图片 =
    "data:image/png;base64," +
    "iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAA4pSURBVHic3Vx5TFTXF/7uDDs4w1Bkh6HUCLFVo0Bi0bTUtBlN06itNG2RxhiMXagFqZjGiphALSokLUabUGJsI/7R1mpiF2sjSlohBW2JtbZAmzKK6MggqywD835/+HvTd+fdt8wwM2C/hIR37nn3nvneudu5CwkPD+cwDRBCmHKO42AwGJCdnY0nnnhCUs/bGB0dxZkzZ/Djjz9iampKlC60i+M4kVwoY71LvEFgSEgI8vPzkZycLKnjDI7j0N7ejq6uLpjNZgwMDMBut2NychIA4OfnB39/f8ydOxdxcXF49NFHERUVpdrO8fFxNDQ04MyZM6p+g9AuKXiEQCECAgKQk5ODzMxMWb2pqSkMDg6iubkZDQ0NsNls0yo3MjISJpMJqampmDNnjqJ+fX09WlpaplUmIQQcx3mOwGXLlmHdunUIDAyU1Onq6sLFixdx6dIlZnXyBPR6PZYvX46srCyEhoZK6g0NDaGmpgZ37txxuQxh9fYIgbt27UJERARVAO/6hBC0trbixIkTGB0ddeiw2htPghCC6OhobNq0CXPnzmXqcByHc+fO4fTp06rzFMn0ej3n7g9ISkr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TqdDYmIi9eLjjz+O69evu3X72WzEyy+/jOXLl4vkBw8elN10JSIQEHvi1atXmXerpKeno6ury+X7pmYTCCHYuHEj87DRJ598onitC5NAPmMh2traYDQaRVfJZWRkgBCCjo6OB649DAwMxPbt2zFv3jxR2meffSY65soC0el0zPGHFBmvv/468/qnW7duoaqqatq3UfoKkZGR2L59O3ON5tNPP3UEC5TgIND5Dis5b8rLyxPND3kcOnRI0e1nElqtFqtWrcIzzzzDTK+rq8OVK1dU50cRKIRSyD4rKwsvvvgiM62zsxNHjhzByMiIakN8gbS0NOTl5TFvbLPZbKiqqnL96j6dTse8P5D3RjkSo6Oj8e677zLTOI7D33//rbhh0hcICQlBYWGh5K2/w8PD2LNnj1vND9Hr9cw2UA2BwP2F5sLCQtnF7ObmZpw9e9Yre7ClQAhBcnIyXnrpJURHRzN1OI7Dd999x7waWXU5Up2I0BBhgayqDty/DuSVV14RTYGEuHHjBpqamvDTTz+J0qazyidEaGgoTCYT0tPTZW/x7e/vR01NzbQ/qssESsl4eW5urqp1ZbvdjlOnTqGxsZE6RekO9Ho91q5di8WLF6vaVVFbW6t4IFEtVBMo1UOz1g/mzJmDDRs2MIc7UhgfH4fZbEZXV5djidJms1HEBgUFQafTITY2FklJSUhISFC9DWVsbAznzp3D999/r9omNVAkkPmSzLlgIblhYWFYuXIlsrOzvbrfRg7j4+P48ssvcfnyZbfud1WCWwRKZiZTBePj47F582bo9Xqvz1impqbQ3d2Nuro6rwc8mAS6e7RfLTELFixARkYGUlJSPLJUYLfbYbFYcO3aNbS0tKi6PNZTUCQQUEei0uUOUul8uxYREYHU1FQ8/PDDiI2NRUBAAPNDjoyMwGw2w2w2O+43HRgY8Nrd/Er4H0KsLQ5iO8/wAAAAAElFTkSuQmCC";
  找图(圈X图片);
}
function 点击赚钱() {
  let 去赚钱 = text("去赚钱")
    .boundsInside(width / 2, height / 5, width, height)
    .findOne(1000);
  if (去赚钱) {
    clickCenter(去赚钱);
  }
}

function 抖音极速版逛逛() {
  showFLog("===开始抖音极速版任务===");
  let nowTime = new Date().getTime();
  launchApp("抖音极速版");
  // 刷视频("抖音极速版");
  let 两次运行时间差 = nowTime - 记录运行时间;
  log(两次运行时间差);
  if (记录运行时间 == 0 || nowTime - 记录运行时间 > 两次运行时间差) {
    去桌面("抖音极速版逛逛任务开始");
    let 需要找小红包 = true;
    if (findAndClick("开宝箱|赚金币|桌面奖励", 10000)) {
      log("等待小红包出现");
      sleepT(5);
      if (找字(/看广告/, [100, 1300, 800, 600])) {
        let 等待时间 = widgetGetOne(".*后可领奖励.*");
        等待并返回(等待时间);
        findAndClick(".*开心收下.*");
      }
    } else {
      showFLog("没查询到小控件，请长按桌面-》卡片服务-》下拉找（窗口小工具=》抖音极速版=》找到（脚本助手）=》长按它 =》添加到桌面");
      launchApp("抖音极速版");
    }
    sleep(3000);
    if (currentPackage() != "com.ss.android.ugc.aweme.lite") {
      log("没有打开抖音");
      launchApp("抖音极速版");
    }
    findAndClick(".*知道了.*");
    widgetCheck("关注");
    if (需要找小红包) {
      showFLog("~~~~~查询抖音小红包~~~");
      let 抖音红包 =
        "data:image/png;base64," +
        "iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAABACSURBVGiBZVpJbxxVFz31ap6r21OIJQwEBSWwi0hggSArBoktQvwaJP4UvwCWIIuESEmkKCFOPHV3zXPVtzDn0tbnFTjtV6/uu/dMr7VffvllbtsWZVmiqioopWDbNuZ5hq7r0DQNeZ7DsizM8wzbtgEAl5eX8H0f0zShKAoEQYCiKDDPM5IkQdu2ME0Tuq6jLEtM0wTDMGAYBsZxhGEYAICiKOA4DqZpwjAM0DQN4ziCP47jwLZtdF2Htm0xjiN0XZf1mqaB7/tQfLhSCtM0ycPbtsU8z2iaBp7nwbZtTNOENE1R1zVM00RVVZimCZqmQdd1LBYLeJ6HzWYDwzCg6zqqqoJlWfLSXdfJxquqQhRFMAwDXdchiiLYtg3TN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fj/jGBJvhSScRyLmCTKbWtDADDYm2EYoqoqEYp8Y4o8ohedHueDILCdZaVpKpqLme8wDAKvhGiGF6y+67py8jR5jFepmrkX6i3OraICpVHhmzuOI0FEEATizS3LEpKMokgqxJakAGSbbWe+DBsoWXjSbB2RG/8i4vZdJBUG1yToMINWdFy86CGaEEIpELeHnIEEhSFZnmqWVwK6rgsaUc5sX3gyiirLUp7B22CSNGdis9nIM6IoEh4Sh8gFyBFcpK5r+L5/7W6dyEMjxpPivQe/z7K9KX6OiGaaJjabDTabDSzLwmKxkC8juK4r2RWVBAmWPzy9bUsxTRMM6ir+ggqYQ0p425bvhFDeg/i+LxumHquqSqwv8yxGTp7nyfdY8jxHFEUyC9wP57EsSzFf3Mt2fizhA40P+44WlyEa24WMzTtzyhP6eH7lgpAbhqFYXs5WnueCVhx0wrLneQIsLBDnjYXmGgyzCSBlWV59F4XQyH/gIn3fy9DTrzOL4oUQdZWmadhsNgLR2/KCVwlsFQ4o71DyPJd2CcMQcRxLyMHoiMk9cBWAU3V7nnd12lShzJjoy8m0jPjpHZhbMVjmFww4P7SznBWeZhiGUnHqOZJfkiQCCLwbjKJIfArnkKjVti2SJJHb5bIsoeSe+l+EWa/X4vYIh/w3emoO/ziO18IEBhbUZfTz5JQwDBGGoXzbh76GwQKNFM3Xdm7ANiYw0Mdw//8D+jJBttj7onwAAAAASUVORK5CYII=";
      找图(抖音红包);
      showFLog("~~~查询开宝箱~~~");
      // 抖音开宝箱();
    }
    showFLog("等待5秒,查询签到");
    sleep(5000);
    if (找字(/签到/, [100, 1300, 800, 600])) {
      sleep(3000);
      if (找字(/看广告/, [100, 1300, 800, 600])) {
        let 等待时间 = widgetGetOne(".*后可领奖励.*");
        等待并返回(等待时间);
        findAndClick(".*开心收下.*");
      }
    }
    showFLog("等待3秒,查询开宝箱");
    sleep(3000);
    逛街();
    if (找字(/开宝箱/, [700, 2100, 300, height - 2100])) {
      sleep(3000);
      if (找字(/看广告视频/, [200, 1300, 700, 300])) {
        let 等待时间 = widgetGetOne(".*后可领奖励.*");
        等待并返回(等待时间);
      }
    }
    if (找字(/看广告视频/, [200, 1300, 700, 300])) {
      let 等待时间 = widgetGetOne(".*后可领奖励.*");
      等待并返回(等待时间);
    }

    className("android.widget.ScrollView")
      .scrollable()
      .find()
      .forEach((v) => {
        v.scrollForward();
      });
    sleep(1000);
    swipex();
    逛街();
    抖音极速版搜索();
    killApp("抖音极速版");
    去桌面("抖音极速版逛逛任务开始");
    if (findAndClick("开宝箱|赚金币|桌面奖励", 10000)) {
      刷视频("抖音极速版");
    }

    记录运行时间 = nowTime;
  }
  showFLog("===结束抖音极速版任务===");
}

function 找图(str, loop) {
  if (typeof loop === "undefined") {
    loop = 3;
  }
  var screen = images.captureScreen();
  screen = images.cvtColor(images.grayscale(screen), "GRAY2BGRA");
  var p = findImage(screen, images.fromBase64(str), { threshold: 0.6 });
  if (p) {
    toastLog("找到啦:" + p);
    let num = p.toString().replace(/{|}/g, "");
    let nums = num.split(",");
    click((nums[0] * 10) / 10, (nums[1] * 10) / 10);
    log("点击坐标：" + (nums[0] * 10) / 10 + " " + (nums[1] * 10) / 10);
    return true;
  } else if (loop-- > 1) {
    sleep(500);
    log("没查询到开始倒数第: b  " + loop + " 找图");
    return 找图(str, loop);
  } else {
    toastLog("没找到，找图失败");
    return false;
  }
}
function 处理开心收下(开心收下) {
  clickCenter(开心收下);
  sleep(1000);
  if (开心收下 && 开心收下.text() == "开心收下") {
  } else if (开心收下) {
    let 等待时间 = widgetGetOne(".*后可领奖励.*");
    等待并返回(等待时间);
  }
}
function 等待并返回(等待时间) {
  if (等待时间) {
    sleep(Number(等待时间.text().replace(/[^\d]/g, "")) * 1000);
    back();
    sleep(3000);
    back();
    findAndClick("坚持退出");
    findAndClick("开心收下");
  }
}

function swipex(speed) {
  从下往上滑动(speed);
}
function 从下往上滑动(阅读文章速度) {
  log(arguments.callee.name + "开始");
  var 阅读文章速度 = 阅读文章速度 || 2.5;
  var w = device.width;
  var h = device.height;
  var x1 = Math.floor((w / 5) * 2);
  var y1 = Math.floor((h / 5) * 3);
  var x2 = Math.floor((w / 5) * 1);
  var y2 = Math.floor((h / 5) * 阅读文章速度);
  var duration = 300;
  swipeRnd(x1, y1, x2, y2, duration);
}
function swipeRnd(x1, y1, x2, y2, duration) {
  var k = 20;
  var x1 = x1 + random(-k, k);
  var y1 = y1 + random(-k, k);
  var x2 = x2 + random(-k, k);
  var y2 = y2 + random(-k, k);
  var duration = duration + random(-k, k);
  swipeRnd2(x1, y1, x2, y2, duration);
}
function swipeRnd2(x1, y1, x2, y2, duration) {
  log(x1 + " " + y1 + " " + x2 + " " + y2);
  gesture(duration, [x1, y1], [x1 + 60, y1 - 80], [x2, y2]);
}
function 逛街() {
  sleep(3000);
  if (找字(/逛街赚钱/, [100, 100, 500, height - 300])) {
    findAndClick("我知道了");
    while (widgetGetOne(".*秒")) {
      sleep(5000);
      swipex();
    }
    back();
    sleep(1000);
    back();
  }
}
/**
 * 根据内容获取一个对象
 *
 * @param {string} contentVal
 * @param {number} timeout 默认超时时间5秒
 * @param {boolean} containType 是否带回类型
 * @param {boolean} suspendWarning 是否隐藏warning信息
 * @param {function} appendFilter 附加查询条件 详见UiSelector
 */
function widgetGetOne(contentVal, timeout, containType, suspendWarning, appendFilter, options) {
  let target = null;
  let isDesc = false;
  let waitTime = timeout || 8000;
  let timeoutFlag = true;
  showFLog(["try to find one: {} timeout: {}ms", contentVal.toString(), waitTime]);
  let checkResult = widgetCheck(contentVal, waitTime, true, appendFilter, options);
  if (!checkResult.timeout) {
    timeoutFlag = false;
    target = checkResult.target;
    isDesc = checkResult.isDesc;
  }
  // 当需要带回类型时返回对象 传递target以及是否是desc
  if (target && containType) {
    let result = {
      target: target,
      bounds: target.bounds(),
      isDesc: isDesc,
      content: isDesc ? target.desc() : target.text(),
    };
    return result;
  }
  return target;
}

/**
 * 替换控件搜索算法DFS,BFS,VDFS,VBFS,PDFS,PBFS,PVDFS,PVBFS
 * DFS,BFS为默认提供的深度优先和广度优先搜索算法
 * VDFS,VBFS为我修改的只搜索可见控件（控件包括父级不可见则直接跳过）深度优先和广度优先搜索算法 缺点是无法搜索不可见控件，适合一个界面中有巨量控件的时候用于加快搜索速度 实际数据抖音极速版从25s缩短到3s
 * PDFS,PBFS,PVDFS,PVBFS 是通过多线程搜索控件 大大加快搜索速度
 *
 * @param {string} algorithm 搜索算法DFS,BFS,VDFS,VBFS,PDFS,PBFS,PVDFS,PVBFS
 * @param {UiSelector} mselector
 * @returns
 */
function wrapSelector(algorithm, appendFilter, mselector) {
  appendFilter =
    appendFilter ||
    function (matcher) {
      return matcher;
    };
  mselector = appendFilter(mselector || selector());
  if (!algorithm) {
    return mselector;
  }
  // if (!algorithm_change_support) {
  //     log(['当前版本不支持替换搜索算法'])
  //     return mselector
  // }
  current = this.getCurrentAlgorithm();
  if (current == algorithm) {
    return mselector;
  }
  log(["替换搜索算法为：{} 原始算法：{}", algorithm, current]);
  return AlgorithmChanger.changeAlgorithm(mselector, algorithm);
}

/**
 * 查找一个子控件中的目标对象
 * @param {UiObject} container 父控件
 * @param {String} contentVal 控件文本
 * @param {number} timeout 超时时间 默认5秒
 * @param {Boolean} containType 返回结果附带文本是desc还是text
 * @param {function} appendFilter 附加查询条件 详见UiSelector
 * @param {Object} options 额外参数
 * 超时返回false
 */
function subWidgetGetOne(container, contentVal, timeout, containType, appendFilter, options) {
  options = options || {};
  timeout = timeout || 5000;
  let countDown = new java.util.concurrent.CountDownLatch(1);
  let matchRegex = new RegExp(contentVal);
  let isDesc = false;
  let isText = false;
  let target = null;
  let descThread = threads.start(function () {
    let descTarget = wrapSelector(options.algorithm, appendFilter).descMatches(matchRegex).findOneOf(container);
    if (descTarget) {
      log(["find desc {} {}", contentVal, descTarget.desc()]);
      isDesc = true;
      target = descTarget;
      countDown.countDown();
    }
  });

  let textThread = threads.start(function () {
    let textTarget = wrapSelector(options.algorithm, appendFilter).textMatches(matchRegex).findOneOf(container);
    if (textTarget) {
      log(["find text {} {}", contentVal, textTarget.text()]);
      isText = true;
      target = textTarget;
      countDown.countDown();
    }
  });

  let isTimeout = false;
  let timeoutThread = threads.start(function () {
    sleep(timeout);
    isTimeout = true;
    countDown.countDown();
  });

  countDown.await();
  descThread.interrupt();
  textThread.interrupt();
  timeoutThread.interrupt();
  if (isTimeout || (!isDesc && !isText)) {
    log("cannot find any matches " + contentVal);
  }
  if (target && containType) {
    return {
      isDesc: isDesc,
      target: target,
      bounds: target.bounds(),
      content: isDesc ? target.desc() : target.text(),
    };
  }
  return target;
}

/**
 * 查找一个子控件中的目标对象
 * @param {UiObject} container 父控件
 * @param {String} contentVal 控件id
 * @param {number} timeout 超时时间 默认5秒
 * @param {Boolean} containType 返回结果附带文本是desc还是text
 * @param {function} appendFilter 附加查询条件 详见UiSelector
 * @param {Object} options 额外参数
 * 超时返回false
 */
function subWidgetGetById(container, contentVal, timeout, containType, appendFilter, options) {
  options = options || {};
  timeout = timeout || 5000;
  let countDown = new java.util.concurrent.CountDownLatch(1);
  let matchRegex = new RegExp(contentVal);
  let isDesc = false;
  let isText = false;
  let target = null;
  let descThread = threads.start(function () {
    let descTarget = wrapSelector(options.algorithm, appendFilter).id(matchRegex).findOneOf(container);
    if (descTarget) {
      log(["find id {} {}", contentVal, descTarget.desc()]);
      isDesc = true;
      target = descTarget;
      countDown.countDown();
    }
  });

  let isTimeout = false;
  let timeoutThread = threads.start(function () {
    sleep(timeout);
    isTimeout = true;
    countDown.countDown();
  });

  countDown.await();
  descThread.interrupt();
  timeoutThread.interrupt();
  if (isTimeout || (!isDesc && !isText)) {
    log("cannot find any matches " + contentVal);
  }
  if (target && containType) {
    return {
      isDesc: isDesc,
      target: target,
      bounds: target.bounds(),
      content: isDesc ? target.desc() : target.text(),
    };
  }
  return target;
}

/**
 * 校验控件是否存在，并打印相应日志
 * @param {String} idRegex 控件文本
 * @param {String} position 日志内容 当前所在位置是否成功进入
 * @param {Number} timeoutSetting 超时时间 默认为 5秒
 */
function idWaiting(idRegex, position, timeoutSetting, appendFilter, options) {
  options = options || {};
  let waitingSuccess = idCheck(idRegex, timeoutSetting, false, appendFilter, options);
  position = position || idRegex;
  if (waitingSuccess) {
    log("等待控件成功：" + position);
    return true;
  } else {
    log("等待控件[" + position + "]失败， id：" + idRegex);
    return false;
  }
}

/**
 * id检测
 * @param {string|RegExp} idRegex
 * @param {number} timeoutSetting
 */
function idCheck(idRegex, timeoutSetting, containType, appendFilter, options) {
  options = options || {};
  let timeout = timeoutSetting || 5000;
  let timeoutFlag = true;
  let countDown = new java.util.concurrent.CountDownLatch(1);
  let target = null;
  let idCheckThread = threads.start(function () {
    target = wrapSelector(options.algorithm, appendFilter).idMatches(idRegex).findOne();
    log("find id " + idRegex);
    timeoutFlag = false;
    countDown.countDown();
  });

  let timeoutThread = threads.start(function () {
    sleep(timeout);
    countDown.countDown();
  });
  countDown.await();
  idCheckThread.interrupt();
  timeoutThread.interrupt();
  if (timeoutFlag) {
    log(["未能找到id:{}对应的控件", idRegex]);
  }
  if (containType) {
    return {
      timeout: timeoutFlag,
      target: target,
      bounds: target ? target.bounds() : null,
    };
  }
  return !timeoutFlag;
}

/**
 * 校验控件是否存在
 * @param {String} contentVal 控件文本
 * @param {Number} timeoutSetting 超时时间 单位毫秒
 * @param {Boolean} containType 返回结果附带文本是desc还是text
 * @param {Object} options 额外参数
 * 超时返回false
 */
function widgetCheck(contentVal, timeoutSetting, containType, appendFilter, options) {
  options = options || {};
  let timeout = timeoutSetting || 5000;
  let timeoutFlag = true;
  let countDown = new java.util.concurrent.CountDownLatch(1);
  let matchRegex = new RegExp(contentVal);
  let isDesc = false;
  let target = null;
  let descThread = threads.start(function () {
    target = wrapSelector(options.algorithm, appendFilter).descMatches(matchRegex).findOne();
    let res = target.desc();
    log("find desc " + contentVal + " " + res);
    timeoutFlag = false;
    isDesc = true;
    countDown.countDown();
  });

  let textThread = threads.start(function () {
    target = wrapSelector(options.algorithm, appendFilter).textMatches(matchRegex).findOne();
    let res = target.text();
    log("find text " + contentVal + "  " + res);
    timeoutFlag = false;
    countDown.countDown();
  });

  let timeoutThread = threads.start(function () {
    sleep(timeout);
    countDown.countDown();
  });
  countDown.await();
  descThread.interrupt();
  textThread.interrupt();
  timeoutThread.interrupt();
  if (timeoutFlag) {
    log("cannot find any matches " + contentVal + " timeout:" + timeout);
  }
  if (containType) {
    return {
      timeout: timeoutFlag,
      target: target,
      bounds: target ? target.bounds() : null,
      isDesc: isDesc,
    };
  }
  return !timeoutFlag;
}

/**
 * 校验控件是否存在，并打印相应日志
 * @param {String} contentVal 控件文本
 * @param {String} position 日志内容 当前所在位置是否成功进入
 * @param {Number} timeoutSetting 超时时间 单位毫秒 默认为_config.timeout_existing
 */
function widgetWaiting(contentVal, position, timeoutSetting, appendFilter, options) {
  options = options || {};
  let waitingSuccess = widgetCheck(contentVal, timeoutSetting, false, appendFilter, options);
  position = position || contentVal;
  if (waitingSuccess) {
    log("等待控件成功：" + position);
    return true;
  } else {
    log("等待控件[" + position + "]失败, 查找内容：" + contentVal);
    return false;
  }
}

/**
 * 根据id获取控件信息
 * @param {String|RegExp} idRegex id
 * @param {number} timeout 超时时间
 * @return 返回找到的控件，否则null
 */
function widgetGetById(idRegex, timeout, appendFilter, options) {
  options = options || {};
  timeout = timeout || 8000;
  let target = idCheck(idRegex, timeout, true, appendFilter, options);
  if (!target.timeout) {
    return target.target;
  } else {
    return null;
  }
}

function waitFor(action, timeout) {
  let countDown = new java.util.concurrent.CountDownLatch(1);
  let actionSuccess = false;
  let actionThread = null;
  let that = this;
  try {
    let start = new Date().getTime();
    actionThread = threads.start(function () {
      try {
        action();
        actionSuccess = true;
      } catch (e) {
        if (e.javaException instanceof com.stardust.autojs.runtime.exception.ScriptInterruptedException) {
          return;
        }
        warn("action执行异常" + e);
        that.printExceptionStack(e);
      } finally {
        countDown.countDown();
      }
      log(["action执行结束: {} 耗时：{}ms", actionSuccess, new Date().getTime() - start]);
    });
    let waitResult = countDown.await(timeout, java.util.concurrent.TimeUnit.MILLISECONDS);
    log(["waitFor方法执行完毕，action result: {}, wait result: {} cost time: {}ms", actionSuccess, waitResult, new Date().getTime() - start]);
    if (!waitResult) {
      log(["等待操作超时, 操作时间: {}ms", new Date().getTime() - start]);
    }
  } catch (e) {
    this.printExceptionStack(e);
  } finally {
    if (actionThread !== null) {
      actionThread.interrupt();
    }
  }
  return actionSuccess;
}

// let result = widgetUtils.alternativeWidget(/\s*今日签到\s*/, '.*明早7点可领.*', null, true)
// if (result.value === 1) {
/**
 * 判断控件A或者控件B是否存在；超时返回0 找到A返回1 否则返回2
 *
 * @param {string|regex} contentA 控件A的内容
 * @param {string|regex} contentB 控件B的内容
 * @param {number} timeout 超时时间
 * @param {boolean} containContent 是否传递实际内容
 * @param {function} appendFilter 附加查询条件 详见UiSelector
 * @param {object} options 额外参数
 * @return 超时返回0 找到A返回1 否则返回2
 */
function alternativeWidget(contentA, contentB, timeout, containContent, appendFilter, options) {
  options = options || {};
  timeout = timeout || _config.timeout_existing;
  let timeoutFlag = true;
  let countDown = new java.util.concurrent.CountDownLatch(1);
  let matchRegexA = new RegExp(contentA);
  let matchRegexB = new RegExp(contentB);
  let isDesc = false,
    findA = false;
  let res = null,
    target = null;
  let descThreadA = threads.start(function () {
    target = _this.wrapSelector(options.algorithm, appendFilter).descMatches(matchRegexA).findOne();
    res = target.desc();
    log("find desc " + contentA + " " + res);
    timeoutFlag = false;
    isDesc = true;
    findA = true;
    countDown.countDown();
  });

  let textThreadA = threads.start(function () {
    target = _this.wrapSelector(options.algorithm, appendFilter).textMatches(matchRegexA).findOne();
    res = target.text();
    log("find text " + contentA + "  " + res);
    timeoutFlag = false;
    findA = true;
    countDown.countDown();
  });
  let descThreadB = threads.start(function () {
    target = _this.wrapSelector(options.algorithm, appendFilter).descMatches(matchRegexB).findOne();
    res = target.desc();
    log("find desc " + contentB + " " + res);
    timeoutFlag = false;
    isDesc = true;
    countDown.countDown();
  });

  let textThreadB = threads.start(function () {
    target = _this.wrapSelector(options.algorithm, appendFilter).textMatches(matchRegexB).findOne();
    res = target.text();
    log("find text " + contentB + "  " + res);
    timeoutFlag = false;
    countDown.countDown();
  });

  let timeoutThread = threads.start(function () {
    sleep(timeout);
    countDown.countDown();
  });
  countDown.await();
  descThreadA.interrupt();
  textThreadA.interrupt();
  descThreadB.interrupt();
  textThreadB.interrupt();
  timeoutThread.interrupt();
  if (timeoutFlag) {
    log(["cannot find any matches {} or {}", contentA, contentB]);
  }
  // 超时返回0 找到A返回1 否则返回2
  let returnVal = timeoutFlag ? 0 : findA ? 1 : 2;
  if (containContent) {
    return {
      target: target,
      bounds: target ? target.bounds() : null,
      content: res,
      value: returnVal,
    };
  } else {
    return returnVal;
  }
}

// 快速打开("快手极速", "com.kuaishou.nebula", "com.yxcorp.gifshow.HomeActivity")
/**
 * 找到并且点击 如果返回错误就点击中心 返回一个布尔值
 * @param {str} 要找的字符串
 */
function findAndClick(str, sleepTime, waitSleep) {
  waitSleep = waitSleep || 100;
  sleep(waitSleep);
  sleepTime = sleepTime || 8000;
  let widgetGet = widgetGetOne(str, sleepTime);
  if (widgetGet) {
    clickView(widgetGet);
    return widgetGet;
  }
  return false;
}
function clickView(obj) {
  try {
    let originalObj = obj; // 保存最初的控件
    if (originalObj) {
      // 点击最初的控件的中心位置
      if (clickCenter(originalObj)) {
        return sleep(400);
      }
    }
    for (let i = 0; i < 4; i++) {
      if (obj && obj.clickable && obj.click()) {
        log("控件点击成功：");
        break;
      } else {
        console.log("Control not clickable, checking parent");
        obj = obj && obj.parent();
      }
    }
    log("点击结束");
    sleep(1000);
  } catch (error) {
    console.error("按键点击失败：" + error);
  }
}

function clickCenter(obj) {
  sleep(300);
  if (obj.bounds().centerX() > width || obj.bounds().centerY() > height || obj.bounds().centerX() < 0 || obj.bounds().centerY() < 0) {
    showFLog("不可点击范围:" + obj.bounds().centerX() + " " + obj.bounds().centerY());
    return false;
  }
  showFLog(obj.text() + " 点击位置：" + Number(obj.bounds().centerX()) + " " + Number(obj.bounds().centerY()));
  click(Number(obj.bounds().centerX()), Number(obj.bounds().centerY()));
  sleep(500);
  return true;
}
// 杀死后台
function killApp(appName) {
  var name = getPackageName(appName); //通过app名称获取包名
  if (null == name) {
    console.error("没有查询douyjsb");
    return true;
  }
  app.openAppSetting(name); //通过包名打开应用的详情页(设置页)
  sleep(2000); //稍微休息一下，不然看不到运行过程，自己用时可以删除这行
  findAndClick(/强.*|停.*|结.*/);
  findAndClick(/强.*|停.*|结.*/);
  findAndClick(/确定/);
  sleep(3000);
  return false;
}

//================悬浮窗开始================
function FloatyUtil() {
  this.floatyWindow = null;
  this.floatyInitStatus = false;
  this.floatyLock = threads.lock();
  this.floatyCondition = this.floatyLock.newCondition();
}

function init() {
  if (this.floatyInitStatus) {
    return;
  }
  let _this = this;
  threads.start(function () {
    _this.floatyLock.lock();
    try {
      if (_this.floatyInitStatus) {
        return;
      }
      _this.floatyWindow = floaty.rawWindow(
        <frame gravity="left">
          <text id="content" textSize="16dp" textColor="#00ff00" />
        </frame>
      );
      ui.run(function () {
        _this.floatyWindow.setTouchable(false);
        _this.floatyWindow.setPosition(50, 150);
        _this.floatyWindow.content.text("悬浮窗初始化成功");
      });
      _this.floatyInitStatus = true;
    } catch (e) {
      console.error("悬浮窗初始化失败" + e);
      _this.floatyWindow = null;
      _this.floatyInitStatus = false;
    } finally {
      _this.floatyCondition.signalAll();
      _this.floatyLock.unlock();
    }
  });
  _this.floatyLock.lock();
  try {
    if (_this.floatyInitStatus === false) {
      console.info("等待悬浮窗初始化");
      _this.floatyCondition.await();
    }
  } finally {
    _this.floatyLock.unlock();
  }
}

function setInfo(text, position, option) {
  option = option || {};
  if (this.floatyWindow === null) {
    this.init();
  }
  let _this = this;
  ui.run(function () {
    _this.floatyLock.lock();
    try {
      if (position && isFinite(position.x) && isFinite(position.y)) {
        _this.floatyWindow.setPosition(parseInt(position.x), parseInt(position.y) + 100);
      }
      if (text) {
        _this.floatyWindow.content.text(text);
      }
      if (option.textSize) {
        _this.floatyWindow.content.setTextSize(option.textSize);
      }
      if (typeof option.touchable !== "undefined") {
        _this.floatyWindow.setTouchable(option.touchable);
      }
    } finally {
      _this.floatyLock.unlock();
    }
  });
}
//============悬浮窗结束=================
function showFLog(msgLog) {
  let str = msgLog + " ";
  setInfo(str);
  log(msgLog);
}
function 打开快手极速版页面() {
  去桌面("打开快手极速版页面");
  if (!findAndClick("快手开宝箱")) {
    if (launchApp("快手极速版")) {
      findAndClick(".*跳过.*");
      sleep(3000);
      findAndClick("我知道了");
    } else {
      return showFLog("没有安装快手极速版");
    }
  }
  sleep(3000);
  找字(/去赚钱/, [600, 1900, 400, 300]);
  sleep(3000);
  if (找字(/开宝箱/, [600, 1900, 400, height - 1900], "开宝箱")) {
    showFLog("开宝箱成功");
    sleep(1000);
    back();
  } else {
    back();
  }
}

function 抖音极速版搜索() {
  showFLog("~~~~~抖音极速版搜索任务~~~~");
  back();
  sleep(1000);
  if (findAndClick("搜索.*")) {
    sleep(3000);
    评价("衣服" + random(1, 10));
    if (widgetGetOne("浏览.*")) {
      sleep(15000);
    }
    back();
    sleep(2000);
    back();
    sleep(2000);
    back();
  }
}
function idAndClick(str, sleepTime) {
  sleepTime = sleepTime || 8000;
  let widgetGet = widgetGetById(str, sleepTime);
  if (widgetGet) {
    clickView(widgetGet);
    return widgetGet;
  }
  return false;
}

function 找字(str, region, regex) {
  region = region || [];
  log("截图找字：" + str);
  let 图片 = captureScreen();
  if (!图片) {
    sleep(1000);
    log("截图失败，1秒后重新截图");
    图片 = captureScreen();
  }
  let recognizeText = qq.recognizeWithBounds(图片, region, regex);
  图片.recycle();
  log("文字查询结果：" + recognizeText.length);
  for (let v of recognizeText) {
    log(v.bounds + "  " + v.label);
    if (str.test(v.label)) {
      if (region != []) {
        if (
          region[0] < v.bounds.left &&
          region[1] < v.bounds.top &&
          region[2] > v.bounds.right - v.bounds.left &&
          region[3] > v.bounds.bottom - v.bounds.top
        ) {
          log("点击位置" + (v.bounds.left + v.bounds.right) / 2 + " " + (v.bounds.top + v.bounds.bottom) / 2);
          click((v.bounds.left + v.bounds.right) / 2, (v.bounds.top + v.bounds.bottom) / 2);
          return true;
        } else {
          continue;
        }
      }
      log("点击位置" + (v.bounds.left + v.bounds.right) / 2 + " " + (v.bounds.top + v.bounds.bottom) / 2);
      click((v.bounds.left + v.bounds.right) / 2, (v.bounds.top + v.bounds.bottom) / 2);
      return true;
    }
  }
}

function 刷视频(str) {
  launchApp(str);
  for (let index = 10; index > 0; index--) {
    if (str == "抖音极速版") {
      let 滑动啊 = true;
      let 滑动控件 = className("androidx.viewpager.widget.ViewPager").scrollable().find();
      if (滑动控件) {
        滑动控件.forEach((v) => {
          sleep(2000);
          if (滑动啊) {
            v.scrollForward();
            log("控件滑动~:" + v.id());
            滑动啊 = false;
          }
        });
      }

      let 发送消息 = widgetGetOne(".*观看30秒.*|发送消息.*|我知道了.*");
      if (发送消息 && /发送消息/.test(发送消息.text())) {
        back();
      } else if (发送消息 && /我知道了/.test(发送消息.text())) {
        clickCenter(发送消息);
      } else if (发送消息) {
        showFLog("等待30秒");
        index = index + 6;
        sleepT(36);
        //这里点击会去其他app
        back();
      } else {
        if (index % 4 == 0) {
          back();
        }
      }
      showFLog(" 倒数：" + index + " 退出");
      continue;
    } else if (str == "拼多多") {
      scrollForward();
    } else if (str == "快手极速版") {
      scrollForward();
      if (widgetCheck("应用名.*")) {
        findAndClick("评论.*");
        评价("谁下载试过~");
        back();
      }
    } else {
      showFLog("滑动一次");
      swipex(1);
    }
    showFLog("随机等待5-8秒 倒数：" + index + " 退出");
    sleep(random(5000, 8000));
  }
}
function 拼多多() {
  if (!launchApp("拼多多")) {
    return showFLog("没有安装拼多多");
  }
  sleep(3000);
  if (currentPackage() != "com.xunmeng.pinduoduo") {
    home();
    findAndClick("拼多多");
  }
  findAndClick("允许");
  back();
  findAndClick("多多视频", 6000, 1000);
  sleep(3000);
  if (找字(/领取今日/, [200, 1300, 600, 300])) {
    sleep(3000);
    back();
  }
  刷视频("拼多多");
}
function 去桌面(str) {
  showFLog(str);
  home();
  sleep(2000);
}
function 评价(str) {
  str = str || "不错[赞][赞]";
  let 不错 = className("android.widget.EditText").findOne(5000);
  if (不错) {
    不错.click();
  }
  setText(str);
  findAndClick("发送.*|搜索.*");
}
function sleepT(num, str) {
  str = str || "";
  num = num || 1;
  for (let index = num; index > 0; index--) {
    showFLog("等待结束倒计时：" + index + "秒 " + str);
    sleep(1000);
  }
}
